package com.heima.Servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 学生登录
 */
@WebServlet("/LoginStudentServlet")
public class LoginStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取用户名和密码
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        //判断用户名是否为空
        if (username==null||"".equals(username)){
            //如果是空，就重定向到登录页面
            resp.sendRedirect(req.getContextPath()+"/Login.jsp");
            return;
        }
        //如果不为空，则存入到会话域中
        req.getSession().setAttribute("username",username);
        //重定向到首页
        resp.sendRedirect(req.getContextPath()+"/index.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
